# 1、有这样的一个列表，深度不可知，列表里面还会嵌套列表，
# 我想要把这个列表从左到右拼接成一个新的列表，且顺序不变
# 举例：[12,33,[11,22,33,[55,66,99]],[55,66]]
# 变成：[12, 33, 11, 22, 33, 55, 66, 99, 55, 66]
# list1=[12,33,[11,22,33,[55,66,99]],[55,66]]
# def relist(list1:list)->list:
#     new_list = []
#     for i in list1:
#         if isinstance(i,list):
#             new_list.extend(relist(i))
#         else:
#             new_list.append(i)
#     return new_list
#
# print(relist(list1))

# def relist(list1:list)->list:
#     klb = []
#     for i in list1:
#         if isinstance(i,list):
#             klb.extend(relist(i))
#         else:
#             klb.append(i)
#     return klb
#
# print(relist(list1))
# 2、编写装饰器，为多个函数加上认证的功能（用户的账号密码）
#  要求登录成功一次，后续的函数都无需输入用户名和密码
# target = False      # 定义一个目标值
# def login(func):
#     def luoji(*args,**kwargs):
#         global target       # 引用全局变量
#         if target:   # 如果说这个目标值变成了True
#             print("免登录")
#             func(*args,**kwargs)
#         else:
#             user = input("请输入账号：")
#             password = input("请输入密码：")
#             if user == 'admin' and password =='123456':
#                 print("登录成功！")
#                 func(*args,**kwargs)
#                 target = True       # 目标值修改为True
#             else:
#                 print("登录失败！")
#     return luoji
# @login
# def shopping():
#     print("购物，买买买")
# @login
# def eat():
#     print("吃饭，吃吃吃")
target = False
def login(func):
    def luoji(*args,**kwargs):
        global target
        if target:
            print("登录成功")
            func(*args,**kwargs)
        else:
            zhanghao = print("请输入账号")
            mima = print("请输入密码")
            if zhanghao == "admin" and mima == "123456":
                print("登录成功")
                func(*args,**kwargs)
                target = True
            else:
                print("登录失败")
    return luoji
@login
def str2():
    print("123456")
# target = False
# def login(func):
#     def luoji(*args,**kwargs):
#         global target
#         if target:
#             print("免登录")
#             func(*args,**kwargs)
#         else:
#             user = print("请输入账号：")
#             password = print("请输入密码：")
#             if user == 'admin' and password == '123456'
#                 print("登陆成功")
#                 func(*args,**kwargs)
#                 target = True
#             else:
#                 print("登陆失败")
#     return luoji

# 3、请实现一个装饰器，把函数的返回值+100然后返回
# def ints(func):
#     def luoji(*args,**kwargs):
#         a = func(*args,**kwargs)     # func ：要被修饰的老函数
#         return a+100
#     return luoji
# @ints
# def star():
#     return 11
#
# print(star())



# def num(func):
#     def luoji(*args,**kwargs):
#         a=func(*args,**kwargs)
#         return a +100
#     return luoji
# @num
# def stu1():
#     return 1
# print(stu1())

# 4、请实现一个装饰器，通过一次调用使函数重复执行5次
# def times5(func):
#     def luoji(*args,**kwargs):
#         results = []
#         for i in range(5):
#             results.append(func(*args,**kwargs))
#         return results
#     return luoji

# 5、输入任意个字符串,分别实现从小到大输出和从大到小输出
# def sort_strings():
#     strings = input("请输入多个字符串，用空格分隔: ").split()
#     ascending = sorted(strings)
#     descending = sorted(strings, reverse=True)
#     print("\n从小到大排序:", ' '.join(ascending))
#     print("从大到小排序:", ' '.join(descending))
# 6、接收n个数字，求这些参数数字的和
# def ints(*args):
#     sum = 0
#     for i in args:
#         sum += i
#     return sum
# print(ints(1, 2, 3, 4))

# 7、编写一个函数，实现数字的自增（从0开始，每调用一次，数字+1）
# def int1():
#     a = 0
#     def add():
#         nonlocal a
#         a += 1
#         return a
#     return add
#
# a = int1()
# print(a())
# print(a())
# print(a())
# print(a())
